function createXHR(){
 
 if(window.ActiveXObject){
  
  xhrObject = new ActiveXObject("Microsoft.XMLHTTP");
  
 }else if(window.XMLHttpRequest){
  
  xhrObject = new XMLHttpRequest();
 }
}

function MypageCon(id){

	if(id == "Guest"){
		alert("訪問者は見ることが出来ませんLogin、または、会員購入して下さい。");
		return;
	}
	
	location.href="/KOMORIUTA/MyMainServ.do?action=MyList&id=" + id;
	
}

function page(id,number,entriesid){

	location.href="/KOMORIUTA/MyMainServ.do?action=MyList&id=" + id + "&number=" + number + "&entriesid=" + entriesid;
	
}

function startPage(id,number){
	
	location.href="/KOMORIUTA/MyMainServ.do?action=MyList&id=" + id + "&number=" + number;
	
}

function doList(page){
	$("#currentPage").val(page);
	$("#entries").submit();
}


function wholeEntries(id, mypageid){
	location.href="/KOMORIUTA/MyMainServ.do?action=WholeEntries&id=" + id + "&mypageid=" + mypageid;
}

function Add(){

	var textbox = $("#Catetext").val();
	var siz = $("#Categorie option").size();

	if(textbox==""){
		alert("カテゴリを書いてください。");
		return;
	}
	for (var i = 0; i < siz; i++) {
		
		if(textbox == $("#Categorie option:eq("+i+")").text()){
			alert("同じカテゴリがあります。");
			return;
		}
	}
	$("#Categorie").append("<option value='" + $("#Catetext").val() + "'>" + $("#Catetext").val() + "</option>");	 
	$("#Catetext").val("");
}

function Delet(){
	var textbox = $("#Catetext").val();

	if(textbox==""){
		alert("削除するカテゴリを選んで下さい。");
		return;
	}
	
	var lis = $("#Categorie option").index($("#Categorie option:selected"));
	
	$("#Categorie option:eq("+lis+")").remove();
	$("#Catetext").val("");
}

function ManageKategorieDelet(mypageid){
	var textbox = $("#Catetext").val();

	if(textbox==""){
		alert("削除するカテゴリを選んで下さい。");
		return;
	}
	
	var lis = $("#Categorie option").index($("#Categorie option:selected"));
	
	var url = "kategorie=" + textbox + "&mypageid=" + mypageid + "";
	createXHR();
	 
	 $.get("/KOMORIUTA/MyKategoreServ.do?action=kategoriedelet&" + url , function(data) {
	 
	});
	
	$("#Categorie option:eq("+lis+")").remove();
	$("#Catetext").val("");
	
	var nick = $("#nick").val();
	
	manage(nick,mypageid);
}

function ManageKategorieAdd(mypageid){

	var textbox = $("#Catetext").val();
	var siz = $("#Categorie option").size();

	if(textbox==""){
		alert("カテゴリを書いてください。");
		return;
	}
	for (var i = 0; i < siz; i++) {
		
		if(textbox == $("#Categorie option:eq("+i+")").text()){
			alert("同じカテゴリがあります。");
			return;
		}
	}
	var url = "kategorie=" + textbox + "&mypageid=" + mypageid + "";
	createXHR();
	$.get("/KOMORIUTA/MyKategoreServ.do?action=kategorieadd&" + url , function(data) {
		 
	});
	
	$("#Categorie").append("<option value='" + $("#Catetext").val() + "'>" + $("#Catetext").val() + "</option>");	 
	$("#Catetext").val("");
	
	var nick = $("#nick").val();
	
	manage(nick,mypageid);
}

function MM_jumpMenu(){
	$("#Catetext").val($("#Categorie > option:selected").text());
	
}

function Write(){
	 var id = $("#nick").val();
	
	 
	 createXHR();
	 
	 $.get("/KOMORIUTA/MyMainServ.do?action=ajax&id=" + id , function(data) {
		 
	  var result = $(data).find("result").text();
	 
	  if(result == 1){
		  alert("!!");
		  $("#Categorie > option").attr("selected", "selected");
		  $("#form").submit();
	  }else{
		  alert("!!!!");
		  $("#check2").hide("slow");
		  $("#check1").show("slow");
		  $("#nick").val("");
		  return;
	  }
	});
}
	
function manageDefinite(){
	$("#form").submit();
}


function entriWrite(id,mypageid){
	
	location.href="/KOMORIUTA/MyWriteServ.do?action=writeview&id=" + id + "&mypageid=" + mypageid;
	
}

function weitePost(){
	$("#write").submit();
}

function weiteModify(){
	$("#writemodify").submit();
}

function entriModify(id, entriid, mypageid){
	
	location.href="/KOMORIUTA/MyWriteServ.do?action=modify&id=" + id + "&entriid=" + entriid + "&mypageid=" + mypageid;
}

function entriDelet(id, entriid, mypageid){
	
	var currentPage = $("#currentPage").val();
	location.href="/KOMORIUTA/MyWriteServ.do?action=entriDelet&id=" + id + "&entriid=" + entriid + "&mypageid=" + mypageid + "&currentPage="+currentPage;
}


function commentView(entriesid){
	$(".warning").hide();
	var id = $(".nick").val();
	var url = "entriesid=" + entriesid + "";

	$.getJSON("/KOMORIUTA/MyCommentServ.do?action=view&" + url , function(data) {  
	
	$(".commlist"+entriesid).remove(); 
	
	for(var i = 0; i < data.conversion.length;i++){
		var commentnick = data.conversion[i].cblog_nick;
		if(commentnick == id){
			
		    $("#fild"+entriesid).prepend("<div class='commlist"+data.conversion[i].entries_id+"'>"
		    								+"<p id='comid"+ data.conversion[i].id +"' class='commlist' >"
				  							+"by <label class='comtitle'>"+ data.conversion[i].cblog_nick +"</label>"
							  				+" <label class='comdate' >"+ data.conversion[i].cblog_date +"</label>" 
							  				+" <a href=javascript:commentDelet(" + data.conversion[i].id + "," + data.conversion[i].entries_id + ") class='black'>[削除]</a><br /><br />"
							  				+data.conversion[i].cblog_contents + "<br />"
							  				+"</p></div>");
		}else{
			
		    $("#fild"+entriesid).prepend("<div class='commlist"+data.conversion[i].entries_id+"'>"
											+"<p id='comid"+ data.conversion[i].id +"' class='commlist' >"
											+"by <a href=javascript:WriteGo('"+ id +"','"+ data.conversion[i].cblog_nick +"')><label class='comtitle'>"+ data.conversion[i].cblog_nick +"</label></a>"
							  				+" <label class='comdate' >"+ data.conversion[i].cblog_date +"</label>" 
							  				+"<br /><br />"
							  				+data.conversion[i].cblog_contents + "<br />"
							  				+"</p></div>");
		}
	}
	
    $("." + entriesid).html("("+data.conversion.length+")");
    
	});

	var item = $("#fild"+entriesid);
	item.toggle("normal");
}

function commentWrite(mypageid, entriesid){
	$(".warning").hide();
	var commentarea = $(".textarea"+entriesid).val();
	
	if(commentarea == ""){
		$("#check" + entriesid).show("slow");
		$(".textarea" + entriesid).focus();
		return;
	}
	var id = $(".nick").val();
	
	var url = "id=" + id + "&mypageid=" + mypageid + "&entriesid=" + entriesid + "&commentarea=" + commentarea + "";
	
	createXHR();
	$.getJSON("/KOMORIUTA/MyCommentServ.do?action=write&" + url , function(data) {
	
	$(".commlist"+entriesid).remove();   
	
	for(var i = 0; i < data.conversion.length;i++){
		var commentnick = data.conversion[i].cblog_nick;
		if(commentnick == id){
			
		    $("#fild"+entriesid).prepend("<div class='commlist"+data.conversion[i].entries_id+"'>"
		    								+"<p id='comid"+ data.conversion[i].id +"' class='commlist' >"
				  							+"by <label class='comtitle'>"+ data.conversion[i].cblog_nick +"</label>"
							  				+" <label class='comdate' >"+ data.conversion[i].cblog_date +"</label>" 
							  				+" <a href=javascript:commentDelet(" + data.conversion[i].id + "," + data.conversion[i].entries_id + ") class='black'><img src='/KOMORIUTA/Main/image/Blog_Dl.png'></a><br /><br />"
							  				+data.conversion[i].cblog_contents + "<br />"
							  				+"</p></div>");
		}else{
			
		    $("#fild"+entriesid).prepend("<div class='commlist"+data.conversion[i].entries_id+"'>"
											+"<p id='comid"+ data.conversion[i].id +"' class='commlist' >"
											+"by <a href=javascript:WriteGo('"+ id +"','"+ data.conversion[i].cblog_nick +"')><label class='comtitle'>"+ data.conversion[i].cblog_nick +"</label></a>"
							  				+" <label class='comdate' >"+ data.conversion[i].cblog_date +"</label>" 
							  				+"<br /><br />"
							  				+data.conversion[i].cblog_contents + "<br />"
							  				+"</p></div>");
		}
	}
	
    $("." + entriesid).html("("+data.conversion.length+")");
    
	});
}

function commentDelet(commentid, entriesid){
	$(".warning").hide();
	
	createXHR();
	 var url = "commentid=" + commentid + "&entriesid=" + entriesid + "";
 
	 $.get("/KOMORIUTA/MyCommentServ.do?action=delet&" + url , function(data) {
		
		 var result = $(data).find("result").text();
		 
		 $("#comid"+commentid).remove();
		 $("." + entriesid).html("("+result+")");

	 }); 
}

function kategori(id, mypageid, kategore){
	
	location.href="/KOMORIUTA/MyKategoreServ.do?action=kategorie&id=" + id + "&kategore=" + kategore + "&mypageid=" + mypageid;
	
}

function kategoriDate(id, mypageid, kategoredate){
	
	location.href="/KOMORIUTA/MyKategoreServ.do?action=kategoriDate&id=" + id + "&kategoredate=" + kategoredate + "&mypageid=" + mypageid;
	
}

function back(){
	
	location.href="/KOMORIUTA/MyMainServ.do?action=back";
	
}

function backyoung(){
	location.href="/KOMORIUTA/MyMainServ.do?action=backyoung";
}

function definite(id, you){
	
	location.href="/KOMORIUTA/MyMainServ.do?action=definite&id=" + id + "&you=" + you;
	
}

function refusal(id, you){
	
	location.href="/KOMORIUTA/MyMainServ.do?action=refusal&id=" + id + "&you=" + you;
	
}

function manage(id, mypageid){
	
	location.href="/KOMORIUTA/MyMainServ.do?action=manage&id=" + id + "&mypageid=" + mypageid;
}

function amendment(){
	$("#youname").empty();
	$("#youname").prepend("<input id='idnick' type='text' name='nick' />");
	
}